package com.jukte.recipe.db;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.util.ByteArrayBuffer;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

import com.jukte.recipe.models.Category;
import com.jukte.recipe.models.Direction;
import com.jukte.recipe.models.IngGroup;
import com.jukte.recipe.models.Ingredient;
import com.jukte.recipe.models.Note;
import com.jukte.recipe.models.Recipe;
import com.jukte.recipe.models.SubCategory;
import com.jukte.recipe.models.Tips;


public class DataBaseManager {

	static private DataBaseManager instance;
	private Cursor cursor;
	static public void init(Context ctx) {
		if (null==instance) {
			instance = new DataBaseManager(ctx);
		}
	}

	static public DataBaseManager getInstance() {
		return instance;
	}

	private DataBaseHelper helper;
	
	private DataBaseManager(Context ctx) {
		helper = new DataBaseHelper(ctx);
	}

	private DataBaseHelper getHelper() {
		return helper;
	}
	
	public void closeDb()
	{
		getHelper().close();
	}
	
	private byte[] getImage(String fileName) {
		try {
			URL imageUrl = new URL("http://tahminaghani.com/quinoa/raw/"+fileName);
			URLConnection ucon = imageUrl.openConnection();

			InputStream is = ucon.getInputStream();
			BufferedInputStream bis = new BufferedInputStream(is);

			ByteArrayBuffer baf = new ByteArrayBuffer(500);
			int current = 0;
			while ((current = bis.read()) != -1) {
				baf.append((byte) current);
			}

			return baf.toByteArray();
		} catch (Exception e) {
			Log.d("ImageManager", "Error: " + e.toString());
		}
		return null;
	}
	
	// Clear all data
	public void clearTable(String table){
		getHelper().executeDeleteQuery(table, null, null);
	}
	
	
	// ADD DATA TO DB
	public long addCategories(int id, String name, String img_path){
		/*Cursor cursor = getHelper().executeRawQuery("SELECT * FROM categories WHERE id="+id+" AND name='"+name+"' " +
				"AND img_path='"+img_path+"'", null);
		if(cursor.moveToFirst()){
			return cursor.getLong(cursor.getColumnIndex("id"));
		}*/
		
		
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("name", name);
		values.put("img_path", img_path);
		
		return getHelper().insertIntoTable("categories", null, values);
	}
	
	public long addCustomIngredients(int id, String text, int recipe_id){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("text", text);
		values.put("recipe_id", recipe_id);
		
		return getHelper().insertIntoTable("custom_ingredients", null, values);
	}
	
	public long addDirections(int id, String text, int recipe_id, int ordering){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("text", text);
		values.put("recipe_id", recipe_id);
		values.put("ordering", ordering);
		
		return getHelper().insertIntoTable("directions", null, values);
	}
	
	public long addIngGroup(int id, String name, int recipe_id){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("name", name);
		values.put("recipe_id", recipe_id);
		
		return getHelper().insertIntoTable("ing_group", null, values);
	}
	
	public long addIngredients(int id, int is_added_cart, String text, int ing_group_id){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("is_added_cart", is_added_cart);
		values.put("text", text);
		values.put("ing_group_id", ing_group_id);
		
		return getHelper().insertIntoTable("ingredients", null, values);
	}	
	
	public long addNotes(String noteText,int recipeId){
		ContentValues inValNotes = new ContentValues();
		inValNotes.put("text", noteText);
		inValNotes.put("recipe_id", recipeId);
		inValNotes.put("ordering", 0);
		
		return getHelper().insertIntoTable("notes", null, inValNotes);
		
	}
	
	public long addRecipeSubCategoryRelation(int id, int recipe_id, int sub_category_id){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("recipe_id", recipe_id);
		values.put("sub_category_id", sub_category_id);
		
		return getHelper().insertIntoTable("recipe_sub_category_relation", null, values);
	}
	
	public long addRecipe(int has_pdf, int is_added_cart, int id, String name, String description, 
			String serves, String img_path, String thumbnail_img_path, int is_fav){
		/*Cursor cursor = getHelper().executeRawQuery("SELECT * FROM recipes WHERE id="+id+" AND name='"+name+"' " +
				"AND img_path='"+img_path+"' AND thumbnail_img_path='"+thumbnail_img_path+"'", null);
		if(cursor.moveToFirst()){
			return cursor.getLong(cursor.getColumnIndex("id"));
		}*/
		
		
		ContentValues values = new ContentValues();
		values.put("has_pdf", has_pdf);
		values.put("is_added_cart", is_added_cart);
		values.put("id", id);
		values.put("name", name);
		values.put("description", description);
		values.put("serves", serves);
		values.put("img_path", img_path);
		values.put("thumbnail_img_path", img_path);
		values.put("is_fav", is_fav);
		
		return getHelper().insertIntoTable("recipes", null, values);
	}
	
	public long addSubCategories(int id, int category_id, String name){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("category_id", category_id);
		values.put("name", name);
		
		return getHelper().insertIntoTable("sub_categories", null, values);
	}
	
	public long addTips(int id, String text, int recipe_id, int ordering){
		ContentValues values = new ContentValues();
		values.put("id", id);
		values.put("text", text);
		values.put("recipe_id", recipe_id);
		values.put("ordering", ordering);
		
		return getHelper().insertIntoTable("tips", null, values);
	}
	
	public void updateFav(int favValue,int recipeId)
	{
		String sqlString="UPDATE recipes SET is_fav="+favValue+" WHERE  id = "+recipeId;
		getHelper().executeUpdateQuery(sqlString);
	}
	
	public List<Ingredient> getAllIngredients(int recipeId)
	{
		List<Ingredient> items=new ArrayList<Ingredient>();
		List<IngGroup> groups=getAllIngGroupByRecipeId(recipeId);
		for(int i=0;i<groups.size();i++)
			items.addAll(groups.get(i).getIngredients());
		return items;
	}
	
	public List<Ingredient> getIngredientsAddedtoCart(int recipeId)
	{
		List<Ingredient> items=new ArrayList<Ingredient>();
		List<IngGroup> groups=getAllIngGroupByRecipeId(recipeId);
		for(int i=0;i<groups.size();i++)
			for(int j=0;j<groups.get(i).getIngredients().size();j++)
			{
				if(groups.get(i).getIngredients().get(j).getIsAddedToCart()==1)
					items.add(groups.get(i).getIngredients().get(j));
			}
		return items;
	}
	
	public List<Ingredient> getCustomIngredients(int recipeId)
	{
		List<Ingredient> ingredients=new ArrayList<Ingredient>();
		String sqlString="select id,text,recipe_id from custom_ingredients where recipe_id="+recipeId;
		cursor=getHelper().executeRawQuery(sqlString,null);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				if(cursor.moveToFirst()){
			        do{
			        	Ingredient ingredient=new Ingredient();
			        	ingredient.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	ingredient.setText(cursor.getString(cursor.getColumnIndex("text")));
			        	ingredient.setRecipe_id(cursor.getInt(cursor.getColumnIndex("recipe_id")));
			        	ingredients.add(ingredient);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }
		}
		return ingredients;
	}
	
	public List<Ingredient> getAllIngredients_in_Cart(int recipeId)
	{
		List<Ingredient> items=new ArrayList<Ingredient>();
		items=getIngredientsAddedtoCart(recipeId);
		items.addAll(getCustomIngredients(recipeId));
		return items;
	}
	
	public Recipe getRecipeDetailsByDeep(int recipeId)
	{
		Recipe recipe=new Recipe();
		cursor=getHelper().getById("recipes", recipeId);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			            recipe.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	recipe.setName(cursor.getString(cursor.getColumnIndex("name")));
			        	recipe.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			        	recipe.setServes(cursor.getString(cursor.getColumnIndex("serves")));
			        	recipe.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));
			        	recipe.setImgPathThumnail(cursor.getString(cursor.getColumnIndex("thumbnail_img_path")));
			        	recipe.setIsFav(cursor.getInt(cursor.getColumnIndex("is_fav")));
			        	recipe.setHasPdf(cursor.getInt(cursor.getColumnIndex("has_pdf")));
			        	recipe.setIsAddedToCart(cursor.getInt(cursor.getColumnIndex("is_added_cart")));
			        	List<IngGroup> groups=getAllIngGroupByRecipeId(recipeId);
			        	recipe.setIngGroups(groups);
			        	List<Direction> directions=getAllDirectionsByRecipeId(recipeId);
			        	recipe.setDirections(directions);
			        	List<Note> notes=getAllNotesByRecipeId(recipeId);
			        	recipe.setNotes(notes);
			        	List<Tips> tips=getAllTipsByRecipeId(recipeId);
			        	recipe.setTips(tips);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

		}
		return recipe;
	}
	
	
	private List<Tips> getAllTipsByRecipeId(int recipeId) {
		Cursor tipsCursor;
		List<Tips> tips=new ArrayList<Tips>();
		tipsCursor=getHelper().getAllByForeignId("tips", "recipe_id", recipeId);
		if (tipsCursor != null)
		{
			if(tipsCursor.getCount()>0)
				
				if(tipsCursor.moveToFirst()){
			        do{
			        	Tips tip=new Tips();
			        	int tipId=tipsCursor.getInt(tipsCursor.getColumnIndex("id"));
			        	tip.setId(tipId);
			        	tip.setText(tipsCursor.getString(tipsCursor.getColumnIndex("text")));
			        	tip.setRecipeId(tipsCursor.getInt(tipsCursor.getColumnIndex("recipe_id")));
			        	tip.setOrdering(tipsCursor.getInt(tipsCursor.getColumnIndex("ordering")));
			        	tips.add(tip);
			        }while(tipsCursor.moveToNext());
			        tipsCursor.close();
			    }

			
		
		}
		return tips;
	}

	private List<Note> getAllNotesByRecipeId(int recipeId) {
		Cursor notesCursor;
		List<Note> notes=new ArrayList<Note>();
		notesCursor=getHelper().getAllByForeignId("notes", "recipe_id", recipeId);
		if (notesCursor != null)
		{
			if(notesCursor.getCount()>0)
				
				if(notesCursor.moveToFirst()){
			        do{
			        	Note note=new Note();
			        	int noteId=notesCursor.getInt(notesCursor.getColumnIndex("id"));
			        	note.setId(noteId);
			        	note.setText(notesCursor.getString(notesCursor.getColumnIndex("text")));
			        	note.setRecipeId(notesCursor.getInt(notesCursor.getColumnIndex("recipe_id")));
			        	note.setOrdering(notesCursor.getInt(notesCursor.getColumnIndex("ordering")));
			        	notes.add(note);
			        }while(notesCursor.moveToNext());
			        notesCursor.close();
			    }

			
		
		}
		return notes;
	}

	private List<Direction> getAllDirectionsByRecipeId(int recipeId) {
		Cursor directionCursor;
		List<Direction> directions=new ArrayList<Direction>();
		directionCursor=getHelper().getAllByForeignId("directions", "recipe_id", recipeId);
		if (directionCursor != null)
		{
			if(directionCursor.getCount()>0)
				
				if(directionCursor.moveToFirst()){
			        do{
			        	Direction direction=new Direction();
			        	int ingGroupId=directionCursor.getInt(directionCursor.getColumnIndex("id"));
			        	direction.setId(ingGroupId);
			        	direction.setText(directionCursor.getString(directionCursor.getColumnIndex("text")));
			        	direction.setRecipeId(directionCursor.getInt(directionCursor.getColumnIndex("recipe_id")));
			        	direction.setOrdering(directionCursor.getInt(directionCursor.getColumnIndex("ordering")));
			        	directions.add(direction);
			        }while(directionCursor.moveToNext());
			        directionCursor.close();
			    }

			
		
		}
		return directions;
		
	}

	private List<IngGroup> getAllIngGroupByRecipeId(int recipeId) {
		Cursor ingGroupCursor;
		List<IngGroup> temp=new ArrayList<IngGroup>();
		ingGroupCursor=getHelper().getAllByForeignId("ing_group","recipe_id", recipeId);
		if (ingGroupCursor != null)
		{
			if(ingGroupCursor.getCount()>0)
				
				if(ingGroupCursor.moveToFirst()){
			        do{
			        	IngGroup group=new IngGroup();
			        	int ingGroupId=ingGroupCursor.getInt(ingGroupCursor.getColumnIndex("id"));
			        	group.setId(ingGroupId);
			        	group.setName(ingGroupCursor.getString(ingGroupCursor.getColumnIndex("name")));
			        	group.setRecipeId(ingGroupCursor.getInt(ingGroupCursor.getColumnIndex("recipe_id")));
			        	group.setIngredients(getAllIngredientsByGroupId(ingGroupId));
			        	temp.add(group);
			        }while(ingGroupCursor.moveToNext());
			        ingGroupCursor.close();
			    }

			
		
		}
		return temp;
	}

	private List<Ingredient> getAllIngredientsByGroupId(int ingGroupId) {
		Cursor ingredientCursor;
		List<Ingredient> ingredients=new ArrayList<Ingredient>();
		ingredientCursor=getHelper().getAllByForeignId("ingredients","ing_group_id", ingGroupId);
		if (ingredientCursor != null)
		{
			if(ingredientCursor.getCount()>0)
				
				if(ingredientCursor.moveToFirst()){
			        do{
			        	Ingredient ingredient=new Ingredient();
			        	ingredient.setId(ingredientCursor.getInt(ingredientCursor.getColumnIndex("id")));
			        	ingredient.setText(ingredientCursor.getString(ingredientCursor.getColumnIndex("text")));
			        	ingredient.setIngGroupId(ingredientCursor.getInt(ingredientCursor.getColumnIndex("ing_group_id")));
			        	ingredient.setIsAddedToCart(ingredientCursor.getInt(ingredientCursor.getColumnIndex("is_added_cart")));
			        	ingredients.add(ingredient);
			        }while(ingredientCursor.moveToNext());
			        ingredientCursor.close();
			    }

			
		
		}
		return ingredients;
		
		
	}

	public List<Recipe> getAllCartRecipeList()
	{
		//String[] selectionVaribles={String.valueOf(searchKey)};
		List<Recipe> recipes=new ArrayList<Recipe>();
		String sqlString="select RECIPES.id,RECIPES.name,RECIPES.thumbnail_img_path" +
				"		from RECIPES " +
				"		where RECIPES.is_added_cart=1 ORDER BY name";
		cursor=getHelper().executeRawQuery(sqlString,null);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				if(cursor.moveToFirst()){
			        do{
			        	Recipe recipe=new Recipe();
			            recipe.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	recipe.setName(cursor.getString(cursor.getColumnIndex("name")));/*
			        	recipe.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			        	recipe.setServes(cursor.getString(cursor.getColumnIndex("serves")));
			        	recipe.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));*/
			        	recipe.setImgPathThumnail(cursor.getString(cursor.getColumnIndex("thumbnail_img_path")));
			        	//recipe.setIsFav(cursor.getInt(cursor.getColumnIndex("is_fav")));
			        	recipes.add(recipe);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }
		}
		
		return recipes;
	}
	
	
	public List<Recipe> getSearchResult(String searchKey)
	{
		//String[] selectionVaribles={String.valueOf(searchKey)};
		List<Recipe> recipes=new ArrayList<Recipe>();
		String sqlString="select RECIPES.id,RECIPES.name,RECIPES.thumbnail_img_path" +
				"		from RECIPES " +
				"		where RECIPES.name like'%"+searchKey+"%' ORDER BY name";
		cursor=getHelper().executeRawQuery(sqlString,null);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			        	Recipe recipe=new Recipe();
			            recipe.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	recipe.setName(cursor.getString(cursor.getColumnIndex("name")));/*
			        	recipe.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			        	recipe.setServes(cursor.getString(cursor.getColumnIndex("serves")));
			        	recipe.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));*/
			        	recipe.setImgPathThumnail(cursor.getString(cursor.getColumnIndex("thumbnail_img_path")));
			        	//recipe.setIsFav(cursor.getInt(cursor.getColumnIndex("is_fav")));
			        	recipes.add(recipe);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

			
		
		}
		return recipes;
	}
	
	
	public List<Recipe> getAllFav()
	{
		String[] selectionVaribles={String.valueOf(1)};
		List<Recipe> recipes=new ArrayList<Recipe>();
		String sqlString="select RECIPES.id,RECIPES.name,RECIPES.thumbnail_img_path" +
				"		from RECIPES " +
				"		where RECIPES.is_fav=? ORDER BY name";
		cursor=getHelper().executeRawQuery(sqlString,selectionVaribles);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			        	Recipe recipe=new Recipe();
			            recipe.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	recipe.setName(cursor.getString(cursor.getColumnIndex("name")));/*
			        	recipe.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			        	recipe.setServes(cursor.getString(cursor.getColumnIndex("serves")));
			        	recipe.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));*/
			        	recipe.setImgPathThumnail(cursor.getString(cursor.getColumnIndex("thumbnail_img_path")));
			        	//recipe.setIsFav(cursor.getInt(cursor.getColumnIndex("is_fav")));
			        	recipes.add(recipe);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

			
		
		}
		return recipes;
	}
	
	public List<Recipe> getAllRecipeCatId(int catId)
	{
		String[] selectionVaribles={String.valueOf(catId)};
		List<Recipe> recipes=new ArrayList<Recipe>();
		String sqlString="select RECIPES.id,RECIPES.name,RECIPES.thumbnail_img_path,RECIPE_SUB_CATEGORY_RELATION.sub_category_id" +
				"		from RECIPE_SUB_CATEGORY_RELATION,RECIPES " +
				"		where RECIPE_SUB_CATEGORY_RELATION.recipe_id=RECIPES.id " +
				"		AND	RECIPE_SUB_CATEGORY_RELATION.sub_category_id " +
				"		IN (SELECT id FROM SUB_CATEGORIES WHERE category_id=?) ORDER BY RECIPES.name";
		cursor=getHelper().executeRawQuery(sqlString, selectionVaribles);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			        	Recipe recipe=new Recipe();
			            recipe.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	recipe.setName(cursor.getString(cursor.getColumnIndex("name")));/*
			        	recipe.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			        	recipe.setServes(cursor.getString(cursor.getColumnIndex("serves")));
			        	recipe.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));*/
			        	recipe.setImgPathThumnail(cursor.getString(cursor.getColumnIndex("thumbnail_img_path")));
			        	//recipe.setIsFav(cursor.getInt(cursor.getColumnIndex("is_fav")));
			        	
			        	int sub_cat_id = cursor.getInt(cursor.getColumnIndex("sub_category_id"));
			        	if(sub_cat_id == 3 || sub_cat_id==5){
			        		recipe.setVegetarian(true);
			        	}else{
			        		recipe.setVegetarian(false);
			        	}
			        	
			        	recipes.add(recipe);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

			
		
		}
		return recipes;
	}
	
	public List<Recipe> getAllRecipeBySubCatId(int subId)
	{
		String[] selectionVaribles={String.valueOf(subId)};
		List<Recipe> recipes=new ArrayList<Recipe>();
		String sqlString="select RECIPES.id,RECIPES.name,RECIPES.thumbnail_img_path" +
				"		from RECIPE_SUB_CATEGORY_RELATION,RECIPES " +
				"		where RECIPE_SUB_CATEGORY_RELATION.sub_category_id=?" +
				"		AND RECIPE_SUB_CATEGORY_RELATION.recipe_id=RECIPES.id ORDER BY RECIPES.name";
		cursor=getHelper().executeRawQuery(sqlString,selectionVaribles);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			        	Recipe recipe=new Recipe();
			            recipe.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	recipe.setName(cursor.getString(cursor.getColumnIndex("name")));/*
			        	recipe.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			        	recipe.setServes(cursor.getString(cursor.getColumnIndex("serves")));
			        	recipe.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));*/
			        	recipe.setImgPathThumnail(cursor.getString(cursor.getColumnIndex("thumbnail_img_path")));
			        	//recipe.setIsFav(cursor.getInt(cursor.getColumnIndex("is_fav")));
			        	recipes.add(recipe);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

			
		
		}
		return recipes;
	}
	
	
	public List<SubCategory> getAllSubCategoriesByCategoryId(int id)
	{
		List<SubCategory> subCategories=new ArrayList<SubCategory>();
		cursor=getHelper().getAllByForeignId("sub_categories", "category_id", id);
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			        	SubCategory subCat=new SubCategory();
			            
			        	subCat.setId(cursor.getInt(cursor.getColumnIndex("id")));
			        	subCat.setName(cursor.getString(cursor.getColumnIndex("name")));
			        	subCat.setCategoryId(cursor.getInt(cursor.getColumnIndex("category_id")));
			            
			        	subCategories.add(subCat);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

			
		
		}
		
		return subCategories;
	}
	
	public List<Category> getAllcategories()
	{
		List<Category> categories=new ArrayList<Category>();
		cursor=getHelper().getAll("categories");
		if (cursor != null)
		{
			if(cursor.getCount()>0)
				
				if(cursor.moveToFirst()){
			        do{
			            Category cat=new Category();
			            
			            cat.setId(cursor.getInt(cursor.getColumnIndex("id")));
			            cat.setCategoryName(cursor.getString(cursor.getColumnIndex("name")));
			            cat.setImgPath(cursor.getString(cursor.getColumnIndex("img_path")));
			            
			            categories.add(cat);
			        }while(cursor.moveToNext());
			        cursor.close();
			    }

			
		
		}
		
		return categories;
	}

	public void updateCart(int recipeId,int i,List<Ingredient> ingredients)
	{
		updateRecipeAddToCart(recipeId, i);
		updateIngredientsAddToCart(ingredients);
	}
	
	public void updateRecipeAddToCart(int recipeId, int i) {
		String sqlString="UPDATE recipes SET is_added_cart="+i+" WHERE  id = "+recipeId;
		getHelper().executeUpdateQuery(sqlString);
	}

	private void updateIngredientsAddToCart(List<Ingredient> ingredients) {
		
		getHelper().updateIngredientsCart(ingredients);
		
	}
	
	
	public void AddCustomIngredient(Ingredient ingredient)
	{
		String sqlString="insert into custom_ingredients(text,recipe_id) values('"+ingredient.getText()+"',"+ingredient.getRecipe_id()+")";
		getHelper().executeUpdateQuery(sqlString);
	}
	public void deleteCustomIngredient(Ingredient ingredient)
	{
		String sqlString="delete from custom_ingredients where id = "+ingredient.getId();
		getHelper().executeUpdateQuery(sqlString);
	}
}
